﻿using System;
using System.Windows.Forms;

namespace snmpTest
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            label1.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int port = 161;

            if (tbIp.Text != "" && tbOid.Text != "")
            {
                try
                {
                    var get = Snmp.GetSnmp(tbOid.Text, tbIp.Text, port);
                    label1.Text = $"get到的值为:{get}";
                }
                catch (Exception ex)
                {
                    label1.Text = $"出错了:{ex}";
                }
            }
            else
            {
                MessageBox.Show("输入有误！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int port = 161;
            
            if (tbIp.Text != "" && tbOid.Text != "")
            {
                string oid = tbOid.Text;
                string hostIp = tbIp.Text;
                string content = tbContent.Text;

                try
                {
                    Snmp.SetSnmp(oid, hostIp, port, content);
                    label1.Text = $"已将[{oid}]的值修改为[{content}]";
                }
                catch (Exception ex)
                {
                    label1.Text = $"出错了:{ex}";
                }
            }
            else
            {
                MessageBox.Show("输入有误！");
            }
        }
    }
}
